//
//  ServerModel.m
//  魔兽大数据
//
//  Created by 王右 on 2017/11/27.
//  Copyright © 2017年 王右. All rights reserved.
//

#import "ServerModel.h"
#import "BigDataHeader.h"
@implementation ServerModel

+ (NSDictionary *)replacedElementDictionary{
    return @{@"id":@"serverID"};
}

- (NSString *)serverName{
    if (_serverName.length != 0) {
        return _serverName;
    }
    NSDictionary *dic = [self returnServerDataDicWithServerID:_serverID.integerValue - 1];
    return dic[@"name"];
}

- (NSString *)targetServerName{
    if (_targetServerName.length != 0) {
        return _targetServerName;
    }
    NSDictionary *dic = [self returnServerDataDicWithServerID:_serverID.integerValue - 1];
    return dic[@"connected"];
}

- (NSDictionary *)returnServerDataDicWithServerID:(NSInteger )serverID{
    NSString * filePath = [[NSBundle mainBundle] pathForResource:@"server"
                                                          ofType:@"txt"];
    NSError  * error;
    NSString * jsonString = [NSString stringWithContentsOfFile:filePath
                                                      encoding:NSUTF8StringEncoding
                                                         error:&error];
    if (jsonString == nil) {
    }
    NSData  *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
    NSError *err;
    NSArray *arr = [NSJSONSerialization JSONObjectWithData:jsonData
                                                   options:NSJSONReadingMutableContainers
                                                     error:&err];
    NSDictionary *dic = arr[serverID];
    return dic;
}


@end
